﻿Imports System.Data.SqlClient
Public Class decisions
    Public Id As Integer
    Public Num_decision As String
    Public Date_decision As Date
    Public Type As String
    Public Resum As String
    Public Declamation As String
    Public Remarque As String
    Public pret As Boolean
    Public tabligh As Information = Nothing
    Public tanfid As Execution = Nothing
    'Les constructeur --------------------------------


    Sub New(ByVal Id As Integer, ByVal Num_decision As String, ByVal Date_decision As Date, ByVal Type As String, ByVal Resum As String, ByVal Declamation As String, ByVal Remarque As String, ByVal pret As Boolean)
        Me.Id = Id
        Me.Num_decision = Num_decision
        Me.Date_decision = Date_decision
        Me.Type = Type
        Me.Resum = Resum
        Me.Declamation = Declamation
        Me.Remarque = Remarque
        Me.pret = pret
        Me.tabligh = New Information
        Me.tanfid = New Execution
    End Sub

    Sub New()

    End Sub
    'les listes ---------------------------------








    'les fonctions ---------------------------
    Public Sub Ajouter_Info()
        Dim cmd As New SqlCommand("insert into Information values(" & Me.Id & ",@NumInfor,@dteInfor,@dteInscripTribu,@dureeDappel,@observation,GETDATE())", Partager.con)
        'Dim cmd As New SqlCommand("insert into Information values(" & Me.Id & ",@NumInfor,@dteInfor,@dteInscripTribu,@dureeDappel," _
        '& Me.tabligh.idMofawad & ",'dfdsfdfdsf',GETDATE())", Partager.con)

        With Me.tabligh
            cmd.Parameters.Add("@NumInfor", SqlDbType.VarChar).Value = .numInfor
            cmd.Parameters.Add("@dteInfor", SqlDbType.Date).Value = .dteInfor
            cmd.Parameters.Add("@dteInscripTribu", SqlDbType.Date).Value = .dteInscripTribu
            cmd.Parameters.Add("@dureeDappel", SqlDbType.TinyInt).Value = .dureeDappel
            cmd.Parameters.Add("@observation", SqlDbType.VarChar).Value = .observation
        End With

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()
    End Sub
    Public Sub suprimmer_Info()

        Dim cmd As New SqlClient.SqlCommand("delete from Information where id =" & Me.Id, Partager.con)

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()
    End Sub
    Public Sub modifier_Info()

        Dim cmd As New SqlClient.SqlCommand("update Information set numInfor=@numInfor,dteInfor=@dteInfor,dteInscripTribu=@dteInscripTribu," & _
        "dureeDappel=@dureeDappel,observation=@observation where id=" & Me.Id, Partager.con)
        'Dim cmd As New SqlClient.SqlCommand("update Information set numInfor=@numInfor,dteInfor=@dteInfor,dteInscripTribu=@dteInscripTribu," & _
        '                                    "dureeDappel=@dureeDappel,idMofawad=" & Me.tabligh.idMofawad & " where id=" & Me.Id, Partager.con)
        With Me.tabligh
            cmd.Parameters.Add("@numInfor", SqlDbType.VarChar).Value = .numInfor
            cmd.Parameters.Add("@dteInfor", SqlDbType.Date).Value = .dteInfor
            cmd.Parameters.Add("@dteInscripTribu", SqlDbType.Date).Value = .dteInscripTribu
            cmd.Parameters.Add("@dureeDappel", SqlDbType.VarChar).Value = .dureeDappel
            cmd.Parameters.Add("@observation", SqlDbType.VarChar).Value = .observation
        End With


        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

    End Sub
   
    Public Function remplir_Info() As Boolean
        Dim cmd As New SqlClient.SqlCommand("select * from Information where id =" & Me.Id, Partager.con)
        Dim flag As Boolean
        Partager.open()
        Partager.dr = cmd.ExecuteReader
        If Partager.dr.HasRows Then
            While Partager.dr.Read
                With Me.tabligh
                    .id = Partager.dr("id")
                    .numInfor = Partager.dr("numInfor")
                    .dteInfor = Partager.dr("dteInfor")
                    .dteInscripTribu = Partager.dr("dteInscripTribu")
                    .dureeDappel = Partager.dr("dureeDappel")
                    .observation = Partager.dr("observation")
                End With
            End While
            flag = True
        Else
            flag = False
        End If
        Partager.dr.Close()
        Partager.close()
        Return flag
    End Function

  
    '//////////////////////////////////////////////////////////////////////Tanfid Functions

    Public Sub Ajouter_Exec()
        Dim cmd As New SqlCommand("insert into Execution values(" & Me.Id _
        & ",@NumExec,@dteExec,@dteInscripTribu,@resultaExec,@observation,GETDATE())", Partager.con)
        'Dim cmd As New SqlCommand("insert into Information values(" & Me.Id & ",@NumInfor,@dteInfor,@dteInscripTribu,@dureeDappel," _
        '& Me.tabligh.idMofawad & ",'dfdsfdfdsf',GETDATE())", Partager.con)

        With Me.tanfid
            cmd.Parameters.Add("@NumExec", SqlDbType.VarChar).Value = .numExec
            cmd.Parameters.Add("@dteExec", SqlDbType.Date).Value = .dteExec
            cmd.Parameters.Add("@dteInscripTribu", SqlDbType.Date).Value = .dteInscripTribu
            cmd.Parameters.Add("@resultaExec", SqlDbType.VarChar).Value = .resultatExecu
            cmd.Parameters.Add("@observation", SqlDbType.VarChar).Value = .observation
        End With

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()
    End Sub

    Public Sub suprimmer_Exec()

        Dim cmd As New SqlClient.SqlCommand("delete from Execution where id =" & Me.Id, Partager.con)

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()
    End Sub
    Public Sub modifier_Exec()

        Dim cmd As New SqlClient.SqlCommand("update Execution set numExec=@numInfor,dteExec=@dteInfor,dteInscripTribu=@dteInscripTribu," & _
        "resultatExecu=@resultaExec,observation=@observation where id=" & Me.Id, Partager.con)
        'Dim cmd As New SqlClient.SqlCommand("update Information set numInfor=@numInfor,dteInfor=@dteInfor,dteInscripTribu=@dteInscripTribu," & _
        '                                    "dureeDappel=@dureeDappel,idMofawad=" & Me.tabligh.idMofawad & " where id=" & Me.Id, Partager.con)
        With Me.tanfid
            cmd.Parameters.Add("@numInfor", SqlDbType.VarChar).Value = .numExec
            cmd.Parameters.Add("@dteInfor", SqlDbType.Date).Value = .dteExec
            cmd.Parameters.Add("@dteInscripTribu", SqlDbType.Date).Value = .dteInscripTribu
            cmd.Parameters.Add("@resultaExec", SqlDbType.VarChar).Value = .resultatExecu
            cmd.Parameters.Add("@observation", SqlDbType.VarChar).Value = .observation
        End With
        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

    End Sub
    Public Function remplir_Exec() As Boolean
        Dim cmd As New SqlClient.SqlCommand("select * from Execution where id =" & Me.Id, Partager.con)
        Dim flag As Boolean
        Partager.open()
        Partager.dr = cmd.ExecuteReader
        If Partager.dr.HasRows Then
            While Partager.dr.Read
                With Me.tanfid
                    .id = Partager.dr("id")
                    .numExec = Partager.dr("numExec")
                    .dteExec = Partager.dr("dteExec")
                    .dteInscripTribu = Partager.dr("dteInscripTribu")
                    .resultatExecu = Partager.dr("resultatExecu")
                    .observation = Partager.dr("observation")
                End With
            End While
            flag = True
        Else
            flag = False
        End If
        Partager.dr.Close()
        Partager.close()
        Return flag
    End Function


    
End Class
